package org.nnxy.foodboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.nnxy.foodboot.entity.PopularRecipe;
import org.nnxy.foodboot.entity.Recipe;

import java.util.List;

/**
 * 热门食谱Mapper接口
 */
@Mapper
public interface PopularRecipeMapper extends BaseMapper<PopularRecipe> {
    
    /**
     * 获取热门食谱及其详情
     * @param limit 限制条数
     * @return 热门食谱列表
     */
    @Select("SELECT r.* FROM recipe r " +
            "INNER JOIN popular_recipe p ON r.id = p.recipe_id " +
            "WHERE r.del_flag = 0 " +
            "ORDER BY p.rank ASC, p.score DESC " +
            "LIMIT #{limit}")
    List<Recipe> getPopularRecipesWithDetails(Integer limit);
} 